package com.dsh.service;

import com.dsh.mapper.GoodsBrowserLogMapper;
import com.dsh.model.GoodsBrowserLogEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;


@Service
public class GoodsBrowserLogMq {
    @Autowired
    GoodsBrowserLogMapper goodsBrowserLogMapper;

    @RabbitHandler
    @RabbitListener(queues = {"queue_4"})
    public void addGoodsBrowserLog(GoodsBrowserLogEntity browserLog, Message message, Channel channel) throws IOException {
        System.err.println("browserLog="+browserLog);
        long deliveryTag = 0;

        goodsBrowserLogMapper.insert(browserLog);

        try {
            deliveryTag=message.getMessageProperties().getDeliveryTag();
            channel.basicAck(deliveryTag,false);
        } catch (IOException e) {
            e.printStackTrace();
            channel.basicNack(deliveryTag,false,true);
        }

    }

}
